package com.code.demo.novate;

import android.content.Context;

import com.alibaba.fastjson.JSONObject;
import com.code.demo.eventbus.EventLogin;
import com.code.demo.eventbus.EventUpdate;
import com.code.demo.bean.RespBody;
import com.code.demo.bean.Update;
import com.code.demo.ui.common.ToastFactory;

import org.greenrobot.eventbus.EventBus;

/**
 * Created by android on 2018/5/4.
 */

public class NovateResponse {

    public static void dispatchGet(String response, Context context, String type) {
        switch (type) {
            case "ossParam":
                break;
        }
    }

    public static void dispatchPost(String response, Context context, String type) {

        RespBody resp = JSONObject.parseObject(response, RespBody.class);

        if (resp.code != 200) {
            ToastFactory.showToast(context, resp.getMsg());
            return;
        }

        switch (type) {
            case "checkLogin": {
                EventBus.getDefault().post(new EventLogin(resp));
            }
            break;
            case "checkVersion": {
                Update update = JSONObject.parseObject(JSONObject.toJSONString(resp.getData().get("result")), Update.class);
                EventBus.getDefault().post(new EventUpdate(update));
            }
            break;
        }
    }
}
